package com.cyl.manager.ums.service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.cyl.manager.ums.mapper.MemberH5LogMapper;
import com.cyl.manager.ums.domain.MemberH5Log;
import com.cyl.manager.ums.pojo.query.MemberH5LogQuery;

/**
 * H5会员日志采集Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class MemberH5LogService {
    @Autowired
    private MemberH5LogMapper memberH5LogMapper;

    /**
     * 查询H5会员日志采集
     *
     * @param id H5会员日志采集主键
     * @return H5会员日志采集
     */
    public MemberH5Log selectById(Long id) {
        return memberH5LogMapper.selectById(id);
    }

    /**
     * 查询H5会员日志采集列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return H5会员日志采集
     */
    public List<MemberH5Log> selectList(MemberH5LogQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<MemberH5Log> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
        Long memberId = query.getMemberId();
        if (memberId != null) {
            qw.eq("member_id", memberId);
        }
        String loginLocation = query.getLoginLocation();
        if (!StringUtils.isEmpty(loginLocation)) {
            qw.eq("login_location", loginLocation);
        }
        Long deptZbjId = query.getDeptZbjId();
        if (deptZbjId != null) {
            qw.eq("dept_zbj_id", deptZbjId);
        }
        String logtype = query.getLogtype();
        if (!StringUtils.isEmpty(logtype)) {
            qw.eq("logtype", logtype);
        }
        return memberH5LogMapper.selectList(qw);
    }

    /**
     * 新增H5会员日志采集
     *
     * @param memberH5Log H5会员日志采集
     * @return 结果
     */
    public int insert(MemberH5Log memberH5Log) {
    	memberH5Log.setCreateTime(LocalDateTime.now());
        return memberH5LogMapper.insert(memberH5Log);
    }

    /**
     * 修改H5会员日志采集
     *
     * @param memberH5Log H5会员日志采集
     * @return 结果
     */
    public int update(MemberH5Log memberH5Log) {
        return memberH5LogMapper.updateById(memberH5Log);
    }

    /**
     * 批量删除H5会员日志采集
     *
     * @param ids 需要删除的H5会员日志采集主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return memberH5LogMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除H5会员日志采集信息
     *
     * @param id H5会员日志采集主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return memberH5LogMapper.updateDelFlagByIds(ids);
    }
}
